package com.zmx.patients.adapter;

import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.zmx.patients.R;
import com.zmx.patients.pojo.PatientOrder;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderItemAdapter extends BaseAdapterRvList<OrderItemAdapter.ViewHolder, PatientOrder> {


    public OrderItemAdapter(Activity activity) {
        super(activity);
    }

    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, PatientOrder patientOrder) {

        holder.context.setText(patientOrder.getContent());
        holder.doctor_name.setText(patientOrder.getName());
        holder.title.setText(patientOrder.getTitle_name());
        if (patientOrder.getHosp_name() ==null ||patientOrder.getHosp_name().equals("null") ){

            holder.hosp_name.setVisibility(View.GONE);
            Glide.with(mActivity).load(R.mipmap.zjtd_head).into(holder.head);


        }else{

            holder.hosp_name.setText(patientOrder.getHosp_name()+" "+patientOrder.getClass_name());
            Glide.with(mActivity).load(patientOrder.getAvatar()).into(holder.head);

        }

        Log.e("avatar",""+patientOrder.getAvatar());
        //这个是你要转成后的时间的格式
        SimpleDateFormat sdff=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 时间戳转换成时间
//        String date = patientOrder.getAsktime()+"000";
//        String sd = sdff.format(new Date(Long.parseLong(date)));
        holder.time.setText(patientOrder.getAsktime());

        if (patientOrder.getStatus() == 0){

            holder.state.setBackgroundResource(R.mipmap.order_state_a);

        }else{

            holder.state.setBackgroundResource(R.mipmap.order_state_b);

        }

    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {
        ViewHolder holder = new ViewHolder(inflater.inflate(R.layout.adapter_order_item, parent, false));
        return holder;
    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.doctor_head)
        ImageView head;
        @BindView(R.id.doctor_name)
        TextView doctor_name;
        @BindView(R.id.hosp_name)
        TextView hosp_name;
        @BindView(R.id.state)
        ImageView state;
        @BindView(R.id.context)
        TextView context;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.title)
        TextView title;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }

}
